//
// Created by shen on 2024/12/18.
//

#ifndef AEDIT_VIDEODECODER_H
#define AEDIT_VIDEODECODER_H

#include "FFStatus.h"
#include "JavaCallHelper.h"
#include "thread"
#include "SafeQueue.h"
#include "AVFrameQueue.h"
extern "C"{
#include "libavutil/time.h"
#include "libavcodec/avcodec.h"
#include "libavutil/imgutils.h"
#include "libswscale/swscale.h"
};
class VideoDecoder {
public:
    int streamIndex=-1;
    AVCodecContext *avCodecContext = NULL;
    AVCodecParameters *avCodecParameters = NULL;
    FFStatus *status;
    JavaCallHelper *helper;
    std::thread play_thread;
    AVRational time_base;
    double defaultDelayTime = 0.04;
    int fps;
    int seekTime;

    int64_t duration = 0;
    //队列中缓存的帧的数量
    int cacheFrameNum = 60;
public:
    //是否是预览模式
    bool isFramePreview = false;
    double showFrameTimestamp = 0;//拖动预览条后当前显示的帧的时间
    SafeQueue *queue = NULL;
    virtual ~VideoDecoder();
    VideoDecoder(FFStatus *status, JavaCallHelper *helper);
    pthread_mutex_t codecMutex;
    pthread_mutex_t showFrameMutex;
public:
    AVFrameQueue *frameQueue = NULL;
    void setIsFramePreview(bool isFramePreview);
    void play();


};


#endif //AEDIT_VIDEODECODER_H
